package com.pengshun.modules.api.system.controller;


import com.fasterxml.jackson.annotation.JsonView;
import com.pengshun.config.NoRepeatSubmit;
import com.pengshun.modules.api.coal.result.CategoryResult;
import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Second;
import com.pengshun.modules.api.system.domain.CityDto;
import com.pengshun.modules.api.system.service.SystemService;
import com.pengshun.modules.api.system.service.dto.AppVersionDto;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.common.ReslutView;
import com.pengshun.modules.domain.PsSuggest;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

@RestController
@RequiredArgsConstructor
@Api(tags = "系统通用")
@RequestMapping("/api/system/common")
public class SystemController {

    private final SystemService systemService;

    @ApiOperation(value = "系统分类" ,notes = "1:ps_category 表加 车辆类型car_type  车辆长度car_length     煤种种类 coal_category  煤种工艺 technology_coal  煤炭属性coal_info 新闻分类news_category  煤炭分类 coal_purpose   交货方式 coal_delivery_mode  颜色分类(coal_color) 煤矿价格分类(coal_price_time)")
    @GetMapping(value = "/coalCategory")
    @ApiImplicitParam(name = "name", value = "煤炭工艺(technology_coal) 煤炭信息(coal_info) 煤炭种类(coal_type) ", dataType = "string", required = true, paramType = "query")
    public BaseResult selectCoalCategory(@ApiIgnore CategoryResult result) throws Exception {
        BaseResult res = systemService.selectCoalCategory(result.getName());
        return res;
    }
    @ApiOperation(value = "查询客服")
    @GetMapping(value = "/customer")
    public BaseResult customer()  {
        BaseResult res = systemService.selectCustomerList();
        return res;
    }
    @ApiOperation(value = "查询所有商户")
    @GetMapping(value = "/merchant")
    public BaseResult merchant()  {
        BaseResult res = systemService.selectMerchantList();
        return res;
    }

    @ApiOperation(value = "系统公告")
    @GetMapping(value = "/notice")
    public BaseResult selectNotice() {
        BaseResult res = systemService.selectNotice();
        return res;
    }

    @ApiOperation(value = "图片上传")
    @PostMapping(value = "/upload")
    @ApiImplicitParam(name = "path", value = "视频传video。煤炭发布传(coal)认证传(authentication) 评论传(evaluate)", dataType = "string", required = true, paramType = "query")
    public BaseResult upload(@RequestParam MultipartFile avatar, String path) throws Exception {
        BaseResult res = systemService.upload(avatar, path);
        return res;
    }

    @ApiOperation(value = "车辆类型和长度")
    @GetMapping(value = "/getVehicleType")
    public BaseResult getVehicleType() throws Exception {
        BaseResult res = systemService.getVehicleTypeAndLength();
        return res;
    }


    @ApiOperation(value = "所有省份")
    @GetMapping(value = "/province")
    public BaseResult selectAllProvince() throws Exception {
        BaseResult res = systemService.selectAllProvince();
        return res;
    }

    @ApiOperation(value = "根据省份id查询城市")
    @GetMapping(value = "/city")
    @ApiImplicitParam(name = "provinceId", value = "省份id", dataType = "int", required = true, paramType = "query")
    public BaseResult selectCityBy(@ApiIgnore @Validated(value = {Second.class}) CityDto para) throws Exception {
        BaseResult res = systemService.selectCityBy(para.getProvinceId());
        return res;
    }

    @ApiOperation(value = "查询所有城市")
    @GetMapping(value = "/all-city")
    @ApiImplicitParam(name = "cityId", value = "城市id", dataType = "int", required = true, paramType = "query")
    @JsonView(ReslutView.bView.class)
    public BaseResult selectAllCityBy(CityDto para) {
        BaseResult res = systemService.selectAllCityBy(para);
        return res;
    }

    @ApiOperation(value = "模糊查询城市")
    @GetMapping(value = "/find-city")
    @ApiImplicitParam(name = "city", value = "城市id", dataType = "int", required = true, paramType = "query")
    public BaseResult selectByCity(CityDto para) {
        BaseResult res = systemService.selectByCity(para);
        return res;
    }

    @ApiOperation(value = "根据城市id查询区县")
    @GetMapping(value = "/district")
    @ApiImplicitParam(name = "cityId", value = "市id", dataType = "int", required = true, paramType = "query")
    public BaseResult selectDstrictBy(@ApiIgnore @Validated(value = {First.class}) CityDto para) throws Exception {
        BaseResult res = systemService.selectDstrictBy(para.getCityId());
        return res;
    }

    @ApiOperation(value = "查询轮播图")
    @GetMapping(value = "/images")
    @ApiImplicitParam(name = "type", value = "类型(0-加载闪图，1-首页轮播图，2-矿口.3常见问题)4首页邀请图", dataType = "int", required = true, paramType = "query")
    public BaseResult images(Integer type) throws Exception {
        BaseResult res = systemService.selectimages(type);
        return res;
    }

    @ApiOperation(value = "查询版本信息")
    @GetMapping(value = "/app-version")
    public BaseResult appVersion() throws Exception {
        BaseResult res = systemService.appVersion();
        return res;
    }

    @ApiOperation(value = "条件查询")
    @GetMapping(value = "/conditions")
    @ApiImplicitParam(name = "type", value = "1煤矿,2经销商,3煤种,4运输公司,", dataType = "int", required = true, paramType = "query")
    public BaseResult conditions(Integer type) throws Exception {
        BaseResult res = systemService.conditions(type);
        return res;
    }

    @ApiOperation(value = "版本设置")
    @PostMapping(value = "/update-version")
    public BaseResult updateVersion(@Valid AppVersionDto version) throws Exception {
        BaseResult res = systemService.updateVersion(version);
        return res;
    }

    @ApiOperation(value = "联系我们")
    @GetMapping(value = "/contact-ours")
    public BaseResult contactOurs() throws Exception {
        BaseResult res = systemService.contactOurs();
        return res;
    }

    @ApiOperation(value = "公司简介")
    @GetMapping(value = "/introduction")
    public BaseResult introduction() throws Exception {
        BaseResult res = systemService.introduction();
        return res;
    }

    @ApiOperation(value = "反馈建议")
    @PostMapping(value = "/suggest")
    @Authorization
    @NoRepeatSubmit
    @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    public BaseResult suggest(@ApiIgnore @CurrUserInfo User user, PsSuggest suggest) throws Exception {
        suggest.setUserId(user.getId());
        BaseResult res = systemService.suggest(suggest);
        return res;
    }
}
